; *** Rook's Tour
; *** Copyright 2002 Zillions Development
; v.2.0

(version "2.0")
(translate
 ("Rook's Tour 1" "车走棋盘 1") ("Rook's Tour 2" "车走棋盘 2") ("Rook's Tour 3" "车走棋盘 3")
 ("Rook's Tour 4" "车走棋盘 4") ("Rook's Tour 5" "车走棋盘 5") ("Rook's Tour 6" "车走棋盘 6")
 ("Military Tactics" "阅兵式") ("Large Rook's Tour" "吃豆车")
 ("Rook's Tour with Revisiting" "车走棋盘（可回程）")
 ("Queen's Tour 1" "皇后走棋盘 1") ("Queen's Tour 2" "皇后走棋盘 2")
 ("Queen's Tour 3" "皇后走棋盘 3") ("Queen's Tour 4" "皇后走棋盘 4")
 ("14 Straight Moves" "14步大串烧")
 ("Lost King's Tour 3x3" "醉王走棋盘 3x3")
 ("Lost King's Tour 4x4" "醉王走棋盘 4x4")
 ("Lost King's Tour 5x5" "醉王走棋盘 5x5")
)

; You need to purchase Zillions of Games to load this rules file
; Visit the Zillions web site at http://www.zillions-of-games.com

; Another one that could be added...
; "More Mathematical Puzzles of Sam Loyd" edited by Martin Gardner
; p. 29 (#41)
; Move 5 rooks to destinations squares

(define queen-def
   (name Queen)
   (description "后\八方行走，格数不限。")
   (image Player "images\Chess\SHaag\wqueen.bmp")
)

(define rook-def
  (name Rook)
  (help "Rook: slides any number of squares along the row or column.")
  (description "车（Rook）\横直行走，格数不限。")
  (image Player "images\Chess\SHaag\wrook.bmp")
)

(define slide (
  (while (on-board? $1)
     $1
     mark (go from) $1
     (while not-marked? (if not-empty? capture) $1)
     add
  )
))

(define slide2 (
  (while (not-empty? $1)
     $1
     mark (go from) $1
     (while not-marked? capture $1)
     add
  )
))

(define rook-slide (
  $1
  (while (and not-empty? not-goal-position?)
     mark (go from) $1
     (while not-marked? capture $1)
     add
     $1
  )
  (if goal-position?
     mark
     
     ; Set captures and capture-this-turn flag's
     (go from)
     $1
     (while not-goal-position?
        capture (set-position-flag capture-this-turn true) $1
     )
     (set-position-flag capture-this-turn true)

     ; Check if there are any coins left we aren't capturing
	 a1
	 (while (and (or (not-piece? Coin) (position-flag? capture-this-turn)) (on-board? next))
        next
     )

     ; If there aren't any, then allow moving to the goal
     (if (or (not-piece? Coin) (position-flag? capture-this-turn))
        back
        add
     )
  )
))

(define board-defs-8x8
  (image "images\Chess\SHaag\Chess8x8.bmp")
  (grid
    (start-rectangle 5 5 53 53)
    (dimensions
      ("a/b/c/d/e/f/g/h" (49 0)) ; files
      ("8/7/6/5/4/3/2/1" (0 49)) ; ranks
    )
    (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
                (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
                (next 1 0)
    )
  )
  (links next (h1 a2) (h2 a3) (h3 a4) (h4 a5) (h5 a6) (h6 a7) (h7 a8))
)



; "Sam Loyd and His Chess Problems" by Alain C. White
; p.42-43
(game
   (title "Rook's Tour 1")
   (solution "Solutions\Rook's_Tour\Rook'sTour1.zsg")
   (description "目标：吃掉所有的硬币，然后返回原位置。一个格只能经过一次。")
   (history "Rook's Tours can be traced back to the nineteenth century famous problem 
     composer, Sam Loyd.  (Rook Tour 1 is one given by Loyd.)  Rook's Tours are often
     presented in other forms, such as a travelling salesmen who must visit a number
     of cities.  Rook's Tours puzzles were constructed and sold in the form of a grid of 
     nails through which a piece of string could be threaded.  One of these was The
     Oklahoma Puzzle, which used a 6x6 grid.  Its name derived from a story setup
     about an inspector checking lot divisions in Oklahoma.")
   (strategy "This can be solved in 16 moves.  To see a solution, select `Show Solution` under the Help menu.")
   (option "animate captures" false)
   (option "highlight goals" true)
   (players Player)
   (turn-order Player)
   (piece
      (rook-def)
      (moves
         (rook-slide n)
         (rook-slide e)
         (rook-slide s)
         (rook-slide w)
      )
   )
   (piece
      (queen-def)
      (moves
         (slide n)
         (slide e)
         (slide s)
         (slide w)
         (slide ne)
         (slide nw)
         (slide se)
         (slide sw)
      )
   )
   (piece
      (name Lost-King)
      (help "喝醉的国王：八方向1格，但每步必须改变方向")
      (description "喝醉的国王（Lost King）\王走八方1格，但是他喝醉了，所以每一步必须变换方向。")
      (image Player "images\Chess\SHaag\wking.bmp")
      (moves
         (lost-king-shift n)
         (lost-king-shift e)
         (lost-king-shift s)
         (lost-king-shift w)
         (lost-king-shift ne)
         (lost-king-shift nw)
         (lost-king-shift se)
         (lost-king-shift sw)
      )
   )
   (piece
     (name Coin)
     (image Player "images\KnightsTour\heads.bmp")
     (help "点这干嘛，硬币是用来被吃的")  
   )   
   (board 
     (board-defs-8x8)
   )

   (board-setup
     (Player
       (Rook c1))
     (Player
       (Coin off 0 a8 b8 c8 d8 e8 f8 g8 h8
                   a7 b7 c7 d7 e7 f7 g7 h7
                   a6 b6 c6 d6 e6 f6 g6 h6
                   a5 b5 c5 d5 e5 f5 g5 h5
                   a4 b4 c4 d4 e4 f4 g4 h4
                   a3 b3 c3 d3 e3 f3 g3 h3
                   a2 b2 c2 d2 e2 f2 g2 h2
                   a1 b1    d1 e1 f1 g1 h1
               ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Rook (c1))))
   (loss-condition (Player) stalemated )
)

; "The Pengin Book of Curious and Interesting Puzzles" by David Wells
; p. 100 (#300 The Rook's Tour)
; Attributed to Dudeney, 1917, No. 320
;
; "Detectograms and Other Puzzles" by H. A. Ripley
; p. 42-43 (#4)
(variant
   (title "Rook's Tour 2")
   (solution "Solutions\Rook's_Tour\Rook'sTour2.zsg")
   (board-setup
     (Player
       (Rook d4))
     (Player
       (Coin off 0 a8 b8 c8 d8 e8 f8 g8 h8
                   a7 b7 c7 d7 e7 f7 g7 h7
                   a6 b6 c6 d6 e6 f6 g6 h6
                   a5 b5 c5 d5 e5 f5 g5 h5
                   a4 b4 c4    e4 f4 g4 h4
                   a3 b3 c3 d3 e3 f3 g3 h3
                   a2 b2 c2 d2 e2 f2 g2 h2
                   a1 b1 c1 d1 e1 f1 g1 h1
       ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Rook (d4))))
   (loss-condition (Player) stalemated )
)


; "Slocum and Botermans New Book of Puzzles"
; p. 108-109
(variant
   (title "Rook's Tour 3")
   (solution "Solutions\Rook's_Tour\Rook'sTour3.zsg")
   (board-setup
     (Player
       (Rook b2))
     (Player
       (Coin off 0 a8 b8 c8 d8 e8 f8 g8 h8
                   a7 b7 c7 d7 e7 f7 g7 h7
                   a6 b6 c6 d6 e6 f6 g6 h6
                   a5 b5 c5 d5 e5 f5 g5 h5
                   a4 b4 c4 d4 e4 f4 g4 h4
                   a3 b3 c3 d3 e3 f3 g3 h3
                   a2    c2 d2 e2 f2 g2 h2
                   a1 b1 c1 d1 e1 f1 g1 h1
       ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Rook (b2))))
   (loss-condition (Player) stalemated )
)

; "Mathematics and Chess" by Miodrag Petkovic
; p. 55-56
; "The Moscow Puzzles" by Boris A. Kordemsky
; p. 3 (#6 The Gardener's Route)
(variant
   (title "Rook's Tour 4")
   (strategy "This can be solved in 24 moves.  To see a solution, select `Show Solution` under the Help menu.")
   (solution "Solutions\Rook's_Tour\Rook'sTour4.zsg")
   (board-setup
     (Player
       (Rook a8))
     (Player
       (Coin off 0    b8 c8 d8 e8 f8 g8 h8
                   a7 b7 c7 d7 e7 f7 g7 h7
                   a6 b6 c6 d6 e6 f6 g6 h6
                   a5 b5 c5 d5 e5 f5      
                   a4 b4 c4       f4 g4 h4
                         c3 d3 e3 f3 g3 h3
                   a2 b2 c2 d2 e2 f2 g2 h2
                   a1 b1 c1 d1 e1 f1 g1 h1
      ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Rook (a8))))
   (loss-condition (Player) stalemated )
)


; "More Mathematical Puzzles of Sam Loyd" edited by Martin Gardner
; p. 29 (#41)
(variant
   (title "Rook's Tour 5")
   (solution "Solutions\Rook's_Tour\Rook'sTour5.zsg")
   (description "吃掉所有的硬币，最终停在F4位置（有星标记）。一个格只能过一次。")
   (strategy "This can be solved in 17 moves.  To see a solution, select `Show Solution` under the Help menu.")

   (board-setup
     (Player
       (Rook a8))
     (Player
       (Coin off 0    b8 c8 d8 e8 f8 g8 h8
                   a7 b7 c7 d7 e7 f7 g7 h7
                   a6 b6 c6 d6 e6 f6 g6 h6
                   a5 b5 c5 d5 e5 f5 g5 h5
                   a4 b4 c4 d4 e4 f4 g4 h4
                   a3 b3 c3 d3 e3 f3 g3 h3
                   a2 b2 c2 d2 e2 f2 g2 h2
                   a1 b1 c1 d1 e1 f1 g1 h1
       ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Rook (f4))))
   (loss-condition (Player) stalemated )
)


; "Slocum and Botermans New Book of Puzzles"
; p. 108-109
(variant
   (title "Rook's Tour 6")
   (solution "Solutions\Rook's_Tour\Rook'sTour6.zsg")
   (description "吃掉所有的硬币，最终停在G1位置（有星标记）。一个格只能过一次。")
   (strategy "This can be solved in 21 moves.  To see a solution, select `Show Solution` under the Help menu.")

   (board-setup
     (Player
       (Rook a8))
     (Player
       (Coin off 0    b8 c8 d8 e8 f8 g8 h8
                   a7 b7 c7 d7 e7 f7 g7 h7
                   a6 b6 c6 d6 e6 f6 g6 h6
                   a5 b5 c5 d5 e5 f5 g5 h5
                   a4 b4 c4 d4 e4 f4 g4 h4
                   a3 b3 c3 d3 e3 f3 g3 h3
                   a2 b2 c2 d2 e2 f2 g2 h2
                   a1 b1 c1 d1 e1 f1 g1 h1
       ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Rook (g1))))
   (loss-condition (Player) stalemated )
)


(variant
  (title "-")
)


; "Mathematical Puzzles of Sam Loyd" edited by Martin Gardner
; p. 31-32
; "Mathematics and Chess" by Miodrag Petkovic
; p. 22-23
(variant
   (title "Military Tactics")
   (solution "Solutions\Rook's_Tour\MilitaryTactics.zsg")
   (description "吃掉所有的硬币，最终停在F1位置（有星标记）。一个格只能过一次。\\并且，你的路线必须满足：\①第一步向上；\②中途穿过D5和E5之间的边线；\③最后一步必须向下返回F1。")
   (strategy "This can be solved in 15 moves (turning 14 times).  To see a solution, select `Show Solution` under the Help menu.")
   (board 
     (board-defs-8x8)
     (positions (arch 0 0 0 0))
     (dummy arch)
     (zone (name left-of-arch)  (players Player) (positions a5 b5 c5 d5) )
     (zone (name right-of-arch) (players Player) (positions e5 f5 g5 h5) )
   )
   (piece
      (rook-def)
      (moves
         (rook-slide n)
         (rook-slide s)
         (  (set-flag good-start  (in-zone? left-of-arch))
            (while (on-board? e)
               e
               mark (go from) e
               (while not-marked? (if not-empty? capture) e)
               (if (and (flag? good-start) (in-zone? right-of-arch))
                  (capture arch)
               )
               add
            )
         )
         (  (set-flag good-start (in-zone? right-of-arch))
            (while (on-board? w)
               w
               mark (go from) w
               (while not-marked? (if not-empty? capture) w)
               (if (and (flag? good-start) (in-zone? left-of-arch))
                  (capture arch)
               )
               add
            )
         )
      )
   )

   (board-setup
     (Player
       (Rook e1))
     (Player
       (Coin off 0 a8 b8 c8 d8 e8 f8 g8 h8
                   a7 b7 c7 d7 e7 f7 g7 h7
                   a6 b6 c6 d6 e6 f6 g6 h6
                   a5 b5 c5 d5 e5 f5 g5 h5
                   a4 b4 c4 d4 e4 f4 g4 h4
                   a3 b3 c3 d3 e3 f3 g3 h3
                   a2 b2 c2 d2 e2 f2 g2 h2
                   a1 b1 c1 d1    f1 g1 h1
		   arch
      ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Rook (f1))))
   (loss-condition (Player) stalemated )
)


(define rook-slide-large (
  $1
  (while (piece? Ball)
     mark (go from) $1
     (while not-marked? (if not-empty? capture) $1)
     add
     $1
  )
))

; "Merit Variety Puzzles and Games" by Penny Press
; p.85
(variant
   (title "Large Rook's Tour")
   (solution "Solutions\Rook's_Tour\LargeTour.zsg")
   (description "吃掉所有的球即可获胜。")
   (strategy "Though a quick mover, the rook will have to make a lot of small moves.  To 
       see a solution, select `Show Solution` under the Help menu.")
   (piece
      (name Rook)
      (help "Rook: slides any number of squares along the row or column.")
      (description "Rook\A Rook moves any number of squares orthogonally on a rank or a file.")
      (image Player "images\Tafl\RedRook.bmp")
      (moves
         (rook-slide-large n)
         (rook-slide-large e)
         (rook-slide-large s)
         (rook-slide-large w)
      )
   )
   (piece
     (name Ball)
     (help "球：你的目标。")  
     (image Player "images\Maze\Light.bmp")
   )   
   (piece
      (name Block)
      (help "墙：阻挡棋子通过。")
      (image Player "images\Maze\Bush.bmp")
   )
   (board 
     (image "images\KnightsTour\LargeTour.bmp")
     (grid
            (start-rectangle 3 3 25 25)
            (dimensions
                ("a/b/c/d/e/f/g/h/i/j" (22 0)) ; columns
                ("16/15/14/13/12/11/10/9/8/7/6/5/4/3/2/1" (0 22)) ; rows
            )
            (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
	                (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1))
      )
   )

   (board-setup
     (Player
       (Rook j16)
       (Block f15 b14 c14 d14 g14 h14 i13 j13 e12 f12 g12 a11 b11 c11 h11 
             b9 e9 f9 g9 b8 c8 d8 i8 j8 e6 f6 g6 a5 b5 c5 d5 i5 j5 f4 g4 b3 c3 i3
             a1 b1 d1 e1 f1 g1 h1 i1 j1)
       (Ball off 0
               a16 b16 c16 d16 e16 f16 g16 h16 i16
               a15 b15 c15 d15 e15     g15 h15 i15 j15
               a14             e14 f14         i14 j14
               a13 b13 c13 d13 e13 f13 g13 h13
               a12 b12 c12 d12             h12 i12 j12
                           d11 e11 f11 g11     i11 j11
               a10 b10 c10 d10 e10 f10 g10 h10 i10 j10
               a9      c9  d9              h9  i9  j9
               a8              e8  f8  g8  h8
               a7  b7  c7  d7  e7  f7  g7  h7  i7  j7
               a6  b6  c6  d6              h6  i6  j6
                               e5  f5  g5  h5
               a4  b4  c4  d4  e4          h4  i4  j4
               a3          d3  e3  f3  g3  h3      j3
               a2  b2  c2  d2  e2  f2  g2  h2  i2  j2
                       c1)
     )
   )
   (win-condition (Player) (pieces-remaining 0 Ball))
   (loss-condition (Player) stalemated )
)

(define rook-slide-revisiting (
  $1
  (while (not-piece? Block)
     mark (go from) $1
    (while not-marked? (if not-empty? capture) $1)
    add
     $1
  )
))

; "Mathematics and Chess" by Miodrag Petkovic
; p. 56
(variant
   (title "Rook's Tour with Revisiting")
   (solution "Solutions\Rook's_Tour\Rook'sTour7.zsg")
   (description "吃掉所有的硬币，然后返回星标的d5格。不存在一个格只能过一次的限制。")
   (strategy "This can be solved in 13 moves.  To see a solution, select `Show Solution` under the Help menu.")
   (piece
      (rook-def)
      (moves
         (rook-slide-revisiting n)
         (rook-slide-revisiting e)
         (rook-slide-revisiting s)
         (rook-slide-revisiting w)
      )
   )
   (piece
      (name Block)
      (help "墙：阻挡棋子通过。")
      (image Player "images\Chess\Block.bmp")
   )
   (board 
     (image "images\Chess\SHaag\Chess7x7.bmp")
     (grid
       (start-rectangle 5 5 53 53)
       (dimensions
         ("a/b/c/d/e/f/g" (49 0)) ; files
         ("7/6/5/4/3/2/1" (0 49)) ; ranks
       )
       (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
              (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
       )
    )
   )

   (board-setup
     (Player
       (Rook d5)
      (Block b2 d2 f2 b4 d4 f4 b6 d6 f6)
       (Coin off 0 a7 b7 c7 d7 e7 f7 g7
                   a6    c6    e6    g6
                   a5 b5 c5    e5 f5 g5
                   a4    c4    e4    g4
                   a3 b3 c3 d3 e3 f3 g3 
                   a2    c2    e2    g2
                   a1 b1 c1 d1 e1 f1 g1
        )
     )
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Rook (d5))))
   (loss-condition (Player) stalemated )
)

(variant
   (title "-")
)

; "My Best Mathematical and Logic Puzzles" by Martin Gardner
; p.35 (#60 Move the Queen)
; "The Master Book of Mathematical Recreations" by Fred Schuh
; p.336 (#272 Broken line through nine dots)
; "Detectograms and Other Puzzles" by H. A. Ripley
; p.59 (#19)
(variant
   (title "Queen's Tour 1")
   (solution "Solutions\Rook's_Tour\Queen'sTour1.zsg")
   (description "吃掉所有的硬币。")
   (history "This problem is very popular.  It is usually presented in the form
      of drawing lines through dots arranged in a square.")
   (strategy "This can be solved in 4 moves.  The `trick` is that
      the Queen can venture outside of the 9 initial squares.  To see a solution, 
      select `Show Solution` under the Help menu.")
   (board-setup
     (Player
       (Queen a7))
     (Player
       (Coin off 0 a8 b8 c8
                      b7 c7
                      a6 b6 c6
     ))
   )
   (win-condition (Player) (pieces-remaining 0 Coin) )
   (loss-condition (Player) stalemated )
)

; "More Games for the Super Intelligent" by James F. Fixx
; p.54 (#5 Outside Chance)
(variant
   (title "Queen's Tour 2")
   (solution "Solutions\Rook's_Tour\Queen'sTour2.zsg")
   (description "吃掉所有的硬币。")
   (history "This problem is very popular.  It is usually presented in the form
      of drawing lines through dots arranged in a square.")
   (strategy "This can be solved in 6 moves.  The `trick` is that
      the Queen can venture outside of the 9 initial squares.  To see a solution, 
      select `Show Solution` under the Help menu.")
   (board-setup
     (Player
       (Queen a5))
     (Player
       (Coin off 0 a8 b8 c8 d8
                   a7 b7 c7 d7
                   a6 b6 c6 d6
                   b5 c5 d5
       ))
   )
   (win-condition (Player) (pieces-remaining 0 Coin) )
   (loss-condition (Player) stalemated )
)


; "Sam Loyd and His Chess Problems" by Alain C. White
; p.42-43
; "The Penguin Book of Curious and Interesting Puzzles" by David Wells
; p.86-87 (#277)
; "150 Challenging & Instructive Puzzles" by Pierre Berloquin
; p.24 (#36)
(variant
   (title "Queen's Tour 3")
   (solution "Solutions\Rook's_Tour\Queen'sTour3.zsg")
   (description "吃掉所有的硬币并返回原位置。。")
   (history "This puzzle by Sam Loyd appeared in Le Sphinx in March, 1867.  Loyd
      wrote, `The best [unique chess-related puzzle] that I have ever produced
      in that line is the Queen's Tour, which I think is the most difficult
      puzzle extant.`")
   (strategy "Try to slide along lines that capture lots of coins and set
      you up for another good move.  Sometimes you may need to slide beyond
      the last coin or stop before the last coin.\\
      This can be solved in 14 moves.  There are a number of possible
      solutions.  To see a solution, select `Show Solution` under the Help menu.")
   (board-setup
     (Player
       (Queen a1))
     (Player
       (Coin off 0 a8 b8 c8 d8 e8 f8 g8 h8
                   a7 b7 c7 d7 e7 f7 g7 h7
                   a6 b6 c6 d6 e6 f6 g6 h6
                   a5 b5 c5 d5 e5 f5 g5 h5
                   a4 b4 c4 d4 e4 f4 g4 h4
                   a3 b3 c3 d3 e3 f3 g3 h3
                   a2 b2 c2 d2 e2 f2 g2 h2
                      b1 c1 d1 e1 f1 g1 h1
       ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Queen (a1))))
   (loss-condition (Player) stalemated )
)


; "A Mathematical Pandora's Box" by Brian Bolt;
; p.43 (#76)
(variant
   (title "Queen's Tour 4")
   (solution "Solutions\Rook's_Tour\Queen'sTour4.zsg")
   (description "吃掉所有的硬币，然后返回星标位置（c6）。")
   (history "Queen's Tours can be traced back to the famous problem 
      composer, Sam Loyd.")
   (strategy "Try to slide along lines that capture lots of coins and set
      you up for another good move.  Sometimes you may need to slide beyond
      the last coin or stop before the last coin.\\
      This can be solved in 15 moves.  To see a solution, select 
     `Show Solution` under the Help menu.")
   (piece
      (queen-def)
      (moves
         (slide2 n)
         (slide2 e)
         (slide2 s)
         (slide2 w)
         (slide2 ne)
         (slide2 nw)
         (slide2 se)
         (slide2 sw)
      )
   )

   (board-setup
     (Player
       (Queen f3))
     (Player
       (Coin off 0 a8 b8 c8 d8 e8 f8 g8 h8
                   a7 b7 c7 d7 e7 f7 g7 h7
                   a6 b6 c6 d6 e6 f6 g6 h6
                   a5 b5 c5 d5 e5 f5 g5 h5
                   a4 b4 c4 d4 e4 f4 g4 h4
                   a3 b3 c3 d3 e3    g3 h3
                   a2 b2 c2 d2 e2 f2 g2 h2
                   a1 b1 c1 d1 e1 f1 g1 h1
       ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Queen (c6))))
   (loss-condition (Player) stalemated )
)



(variant
   (title "-")
)

; "Sam Loyd and His Chess Problems" by Alain C. White
; p.52 (#56) Sam Loyd's Puzzle Magazine, April 1908
; "The Penguin Book of Curious and Interesting Puzzles" by David Wells
; p.87 (#278)
(define leap2        ($1 $2 (verify (piece? Coin)) add) )
(define leap3        ($1 $2 $3 (verify (piece? Coin)) add) )
(define leap4        ($1 $2 $3 $4 (verify (piece? Coin)) add) )
(define leap5        ($1 $2 $3 $4 $5 (verify (piece? Coin)) add) )
(variant
   (title "14 Straight Moves")
   (solution "Solutions\Rook's_Tour\14StraightMoves.zsg")
   (description "吃掉所有的硬币并返回d1位置。后可以移到任意位置。\
若起点终点连线上经过某些格子的中心，那么这些格子的硬币也会被吃。\举例并提示：最后一步是g7-d1，吃掉f5和e3。")
   (history "This problem was published in `Sam Loyd's Puzzle Magazine`, April 1908.")
   (strategy "The piece can proceed in ANY straight line, not just Queen moves.  You
      can pass over the centers of all squares in this manner in 14 moves.")
   (piece
      (name Queen)
      (description "Piece\The piece moves in a straight line in any direction,
          even if the line doesn't take it throught the center of the squares it passes
	  over.  It can capture a coin in every square it goes through the center of.")
      (image Player "images\Chess\SHaag\wqueen.bmp")
      (moves
         (slide n)  (slide e)  (slide s)  (slide w)  (slide ne) (slide nw) (slide se) (slide sw)
         (slide x1) (slide x2) (slide x3) (slide x4) (slide x5) (slide x6) (slide x7) (slide x8)
         (slide y1) (slide y2) (slide y3) (slide y4) (slide y5) (slide y6) (slide y7) (slide y8)
         (slide z1) (slide z2) (slide z3) (slide z4) (slide z5) (slide z6) (slide z7) (slide z8)
         (leap2 y1 n) (leap2 y2 e) (leap2 y3 s) (leap2 y4 w)
         (leap2 y5 n) (leap2 y6 e) (leap2 y7 s) (leap2 y8 w)
	 (leap2 y1 z1) (leap2 y2 z2) (leap2 y3 z3) (leap2 y4 z4)
	 (leap2 y5 z5) (leap2 y6 z6) (leap2 y7 z7) (leap2 y8 z8)
	 (leap3 y1 n n) (leap3 y2 e e) (leap3 y3 s s) (leap3 y4 w w)
         (leap3 y5 n n) (leap3 y6 e e) (leap3 y7 s s) (leap3 y8 w w)
	 (leap4 y1 n n n) (leap4 y2 e e e) (leap4 y3 s s s) (leap4 y4 w w w)
         (leap4 y5 n n n) (leap4 y6 e e e) (leap4 y7 s s s) (leap4 y8 w w w)
	 (leap5 y1 n n n n) (leap5 y2 e e e e) (leap5 y3 s s s s) (leap5 y4 w w w w)
         (leap5 y5 n n n n) (leap5 y6 e e e e) (leap5 y7 s s s s) (leap5 y8 w w w w)
	 (leap3 y1 y1 n) (leap3 y2 y2 e) (leap3 y3 y3 s) (leap3 y4 y4 w)
         (leap3 y5 y5 n) (leap3 y6 y6 e) (leap3 y7 y7 s) (leap3 y8 y8 w)
	 (leap3 y1 y1 ne) (leap3 y2 y2 se) (leap3 y3 y3 se) (leap3 y4 y4 sw)
         (leap3 y5 y5 nw) (leap3 y6 y6 ne) (leap3 y7 y7 sw) (leap3 y8 y8 nw)
	 (leap2 z1 x1) (leap2 z2 x2) (leap2 z3 x3) (leap2 z4 x4)
	 (leap2 z5 x5) (leap2 z6 x6) (leap2 z7 x7) (leap2 z8 x8)
	 (leap2 z1 y6) (leap2 z2 y3) (leap2 z3 y2) (leap2 z4 y7)
	 (leap2 z5 y8) (leap2 z6 y1) (leap2 z7 y4) (leap2 z8 y5)
	 (leap3 x1 x1 ne) (leap3 x1 x1 n) (leap3 x1 x1 e)
	 (leap3 x2 x2 se) (leap3 x2 x2 s) (leap3 x2 x2 e)
	 (leap3 x3 x3 se) (leap3 x3 x3 s) (leap3 x3 x3 e)
	 (leap3 x4 x4 sw) (leap3 x4 x4 s) (leap3 x4 x4 w)
	 (leap3 x5 x5 nw) (leap3 x5 x5 n) (leap3 x5 x5 w)
	 (leap3 x6 x6 ne) (leap3 x6 x6 n) (leap3 x6 x6 e)
	 (leap3 x7 x7 sw) (leap3 x7 x7 s) (leap3 x7 x7 w)
	 (leap3 x8 x8 nw) (leap3 x8 x8 n) (leap3 x8 x8 w)
	 (leap3 x1 ne ne) (leap3 x2 se se) (leap3 x3 se se) (leap3 x4 sw sw)
	 (leap3 x5 nw nw) (leap3 x6 ne ne) (leap3 x7 sw sw) (leap3 x8 nw nw)
	 (leap3 x1 x1 z6) (leap3 x2 x2 z3) (leap3 x3 x3 z2) (leap3 x4 x4 z7)
	 (leap3 x5 x5 z8) (leap3 x6 x6 z1) (leap3 x7 x7 z4) (leap3 x8 x8 z5)
      )
   )
   (board 
     (image "images\Chess\SHaag\Chess8x8.bmp")
     (grid
       (start-rectangle 5 5 53 53)
       (dimensions
         ("a/b/c/d/e/f/g/h" (49 0)) ; files
         ("8/7/6/5/4/3/2/1" (0 49)) ; ranks
       )
       (directions (n  0 -1) (e  1 0) (s  0 1) (w  -1 0) (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
                   (z1  1 -2) (z2 2  1) (z3  1 2) (z4 -2  1)
                   (z5 -1 -2) (z6 2 -1) (z7 -1 2) (z8 -2 -1)
                   (y1  1 -3) (y2 3  1) (y3  1 3) (y4 -3  1)
                   (y5 -1 -3) (y6 3 -1) (y7 -1 3) (y8 -3 -1)
                   (x1  2 -3) (x2 3  2) (x3  2 3) (x4 -3  2)
                   (x5 -2 -3) (x6 3 -2) (x7 -2 3) (x8 -3 -2)
		   (next 1 0)
       )
     )
   )
   (board-setup
     (Player
       (Queen d1))
     (Player
       (Coin off 0 a8 b8 c8 d8 e8 f8 g8 h8
                   a7 b7 c7 d7 e7 f7 g7 h7
                   a6 b6 c6 d6 e6 f6 g6 h6
                   a5 b5 c5 d5 e5 f5 g5 h5
                   a4 b4 c4 d4 e4 f4 g4 h4
                   a3 b3 c3 d3 e3 f3 g3 h3
                   a2 b2 c2 d2 e2 f2 g2 h2
                   a1 b1 c1    e1 f1 g1 h1
       ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Queen (d1))))
   (loss-condition (Player) stalemated )
)


(variant
   (title "-")
)


(define lost-king-shift (
  (verify (not-last-from? (opposite $1)))
  $1 (verify not-empty?) add
))

; "Penrose Tiles to Trapdoor Ciphers" by Martin Gardner
; p.124-125 (#5)
(variant
   (title "Lost King's Tour 3x3")
   (solution "Solutions\Rook's_Tour\LostKing'sTour3x3.zsg")
   (description "吃掉所有的硬币并走到右下角，国王每一步必须变换方向。")
   (history "This tour was proposed by Scott Kim and published in Martin
      Gardner's column in Scientific American.")
   (strategy "The solution contains 1 crossing.  To see it, select `Show Solution` under the Help menu.")
   (board 
     (image "images\Chess\SHaag\Chess3x3.bmp")
     (grid
       (start-rectangle 5 5 53 53)
       (dimensions
         ("a/b/c" (49 0)) ; files
         ("3/2/1" (0 49)) ; ranks
       )
       (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
                   (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
		   (next 1 0)
       )
     )
   )
   (board-setup
     (Player
       (Lost-King a3))
     (Player
       (Coin off 0    b3 c3
                   a2 b2 c2
                   a1 b1 c1
       ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Lost-King (c1))))
   (loss-condition (Player) stalemated )
)

; "Penrose Tiles to Trapdoor Ciphers" by Martin Gardner
; p.124-125 (#5)
(variant
   (title "Lost King's Tour 4x4")
   (solution "Solutions\Rook's_Tour\LostKing'sTour4x4.zsg")
   (description "吃掉所有的硬币并走到星标位置，国王每一步必须变换方向。")
   (history "This tour was proposed by Scott Kim and published in Martin
      Gardner's column in Scientific American.")
   (strategy "This tour can be solved with only 3 crossings.  To see 
      the (unique) solution, select `Show Solution` under the Help menu.")
   (board 
     (image "images\Chess\SHaag\Chess4x4.bmp")
     (grid
       (start-rectangle 5 5 53 53)
       (dimensions
         ("a/b/c/d" (49 0)) ; files
         ("4/3/2/1" (0 49)) ; ranks
       )
       (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
                   (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
		   (next 1 0)
       )
     )
   )
   (board-setup
     (Player
       (Lost-King b3))
     (Player
       (Coin off 0 a4 b4 c4 d4
                   a3    c3 d3
                   a2 b2 c2 d2
                   a1 b1 c1 d1
       ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Lost-King (c2))))
   (loss-condition (Player) stalemated )
)

; "Penrose Tiles to Trapdoor Ciphers" by Martin Gardner
; p.124-125 (#5)
(variant
   (title "Lost King's Tour 5x5")
   (solution "Solutions\Rook's_Tour\LostKing'sTour5x5.zsg")
   (description "吃掉所有的硬币并走到星标位置，国王每一步必须变换方向。")
   (history "This tour was proposed by Scott Kim and published in Martin
      Gardner's column in Scientific American.")
   (strategy "This tour can be solved with only 2 crossings.  To see 
      the solution, select `Show Solution` under the Help menu.")
   (board 
     (image "images\Chess\SHaag\Chess5x5.bmp")
     (grid
       (start-rectangle 5 5 53 53)
       (dimensions
         ("a/b/c/d/e" (49 0)) ; files
         ("5/4/3/2/1" (0 49)) ; ranks
       )
       (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
                   (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
		   (next 1 0)
       )
     )
   )
   (board-setup
     (Player
       (Lost-King b4))
     (Player
       (Coin off 0 a5 b5 c5 d5 e5
                   a4    c4 d4 e4
                   a3 b3 c3 d3 e3
                   a2 b2 c2 d2 e2
                   a1 b1 c1 d1 e1
       ))
   )
   (win-condition (Player) (and (pieces-remaining 0 Coin) (absolute-config Lost-King (d2))))
   (loss-condition (Player) stalemated )
)


